<template>
  <div class="app-container">
    <el-form class="searchForm" :inline="true" :model="queryForm" label-width="80px">
      <el-form-item label="模板编号">
        <el-input v-model="queryForm.modelcode" prop="modelcode" />
      </el-form-item>
      <el-form-item label="表名">
        <el-input v-model="queryForm.tablename" prop="tablename" />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="queryForm.describe" prop="describe" />
      </el-form-item>

      <el-form-item>
        <el-button type="info" @click="pageChange(1)">查询</el-button>
        <el-button type="info" @click="onAdd">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="tableData"
      element-loading-background="rgba(0, 0, 0, 0.8)"
      height="550"
      stripe
      border
      style="width: 100%"
    >
      <el-table-column :resizable="false" label="操作" width="140" fixed>
        <template slot-scope="scope">
          <span class="edit-tooltip">
            <el-tooltip effect="dark" content="删除" placement="bottom">
              <el-button type="text" @click="onDel(scope.row)">
                <svg-icon style="fill: #ff4e1d" icon-class="butongyi"></svg-icon>
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="修改" placement="bottom">
              <el-button type="text" @click="onClickName(scope.row)">
                <svg-icon style="fill: #ff4e1d" icon-class="a-xiugai"></svg-icon>
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="复制" placement="bottom">
              <el-button type="text" @click="onClickcopy(scope.row)">
                <svg-icon style="fill: #ff4e1d" icon-class="copy"></svg-icon>
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="流程配置" placement="bottom">
              <el-button type="text" @click="onClickprocess(scope.row)">
                <svg-icon style="fill: white" icon-class="Processconfiguration"></svg-icon>
              </el-button>
            </el-tooltip>
          </span>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" prop="modelcode" label="模板编号" min-width="130" />
      <el-table-column :resizable="false" prop="describe" label="描述" min-width="100" />
      <el-table-column :resizable="false" prop="tablename" label="表名" min-width="100" />
      <el-table-column :resizable="false" prop="primarykey" label="主键字段" min-width="100" />
      <el-table-column :resizable="false" prop="agreesql" label="审批通过更新sql" min-width="120" />
      <el-table-column :resizable="false" prop="disagreesql" label="审批拒绝更新sql" min-width="120" />
      <el-table-column :resizable="false" prop="refersql" label="提交后更新sql" min-width="100" />
      <el-table-column :resizable="false" prop="disagreepageurl" label="退回待阅消息点击进入页面地址" min-width="220" />
      <el-table-column
        :resizable="false"
        prop="agreepageurl"
        label="审批通过待阅消息点击进入页面地址"
        min-width="220"
      />
      <el-table-column :resizable="false" prop="agreepagemenu" label="菜单编号" min-width="150" />
      <el-table-column :resizable="false" prop="filemodelcode" label="附件对应模板编号" min-width="150" />
    </el-table>
    <el-pagination
      style="margin: 10px"
      :current-page="queryForm.pagenum"
      :page-sizes="[20, 50, 100]"
      :page-size="queryForm.pagesize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
    <el-dialog
      destroy-on-close
      :title="title"
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="600px"
      @close="onClose"
    >
      <span>
        <el-form ref="form" :model="form" :rules="formRules" label-width="100px" :inline="false">
          <el-form-item label="模板编号" prop="modelcode">
            <el-input v-model="form.modelcode" />
          </el-form-item>
          <el-form-item label="描述" prop="describe">
            <el-input v-model="form.describe" />
          </el-form-item>
          <el-form-item label="表名" prop="tablename">
            <el-input v-model="form.tablename" />
          </el-form-item>
          <el-form-item label="主键字段" prop="primarykey">
            <el-input v-model="form.primarykey" />
          </el-form-item>

          <el-form-item label="审批通过更新sql" prop="agreesql">
            <el-input v-model="form.agreesql" />
          </el-form-item>
          <el-form-item label="审批拒绝更新sql" prop="disagreesql">
            <el-input v-model="form.disagreesql" />
          </el-form-item>
          <el-form-item label="提交后更新sql" prop="refersql">
            <el-input v-model="form.refersql" />
          </el-form-item>
          <el-form-item label="退回待阅消息点击进入页面地址" prop="disagreepageurl">
            <el-input v-model="form.disagreepageurl" />
          </el-form-item>
          <el-form-item label="审批通过待阅消息点击进入页面地址" prop="agreepageurl">
            <el-input v-model="form.agreepageurl" />
          </el-form-item>
          <el-form-item label="菜单编号" prop="agreepagemenu">
            <el-input v-model="form.agreepagemenu" />
          </el-form-item>
          <el-form-item label="附件对应模板编号" prop="filemodelcode">
            <el-input v-model="form.filemodelcode" />
          </el-form-item>
        </el-form>
      </span>
      <div slot="footer">
        <el-button type="info" @click="onSubmit">保存</el-button>
      </div>
    </el-dialog>
    <Processdialog :visibles-s-p="visiblesSP" :datarow="datarow" @visiblesSP="visiblesSP = false"></Processdialog>
  </div>
</template>

<script>
import { QueryPageList, Save, Del, Copy } from '@/api/settings/shenpimoban'
import Processdialog from './shenpimobandialog/Processdialog.vue'
export default {
  name: 'Shenpimoban',
  components: {
    Processdialog
  },

  data() {
    return {
      queryForm: {
        pagenum: 1,
        pagesize: 20
      },
      total: 0,
      tableData: [],
      loading: true,
      visible: false,
      title: '审批模板',
      visible2: false,
      formRules: {
        standtype: [{ required: true, message: '请输入费用类型', trigger: 'blur' }],
        feename: [{ required: true, message: '请输入类型明细', trigger: 'blur' }],
        money: [{ required: true, message: '请输入金额', trigger: 'blur' }]
      },
      form: {},
      datarow: [],
      // 币别子组件弹框显示与隐藏
      currvisible: false,
      // 国家组件弹框显示与隐藏
      nationvisible: false,
      visiblesSP: false
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 点击页面显示条数
    sizeChange(size) {
      this.queryForm.pagesize = size
      this.onSearch()
    },
    // 点击下一页与页码
    pageChange(page) {
      console.log(page)
      this.queryForm.pagenum = page
      this.onSearch()
    },
    // 查询
    async onSearch() {
      this.loading = true
      const list = await QueryPageList(this.queryForm)
      console.log(list)
      this.tableData = list.content.list
      this.total = list.content.total
      this.loading = false
    },
    // 点击添加
    onAdd() {
      console.log(new Date())
      var time = new Date()
      this.form.time = time
      this.visible = true
    },
    // 保存
    onSubmit() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          const res = await Save(this.form)
          if (res.success) {
            if (this.form.id) {
              if (res.message == '操作成功') {
                this.$message({
                  type: 'success',
                  message: '修改数据成功'
                })
              } else {
                this.$message.error(res.message)
              }
            } else {
              if (res.message == '操作成功') {
                this.$message({
                  type: 'success',
                  message: '添加数据成功'
                })
              } else {
                this.$message.error(res.message)
              }
            }
            this.visible = false
            this.onSearch()
          } else {
            this.$message({
              type: 'error',
              message: res.message
            })
          }
        } else {
          return false
        }
      })
    },
    // 点击修改
    onClickName(data) {
      this.visible = true
      this.form = data
    },
    // 关闭弹框
    onClose() {
      this.form = {}
    },
    // 删除
    onDel(data) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const del = await Del({ id: data.id })
          console.log(del)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.queryForm = {
            pagenum: 1,
            pagesize: 20
          }
          this.onSearch()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 复制
    onClickcopy(row) {
      this.$confirm('此操作将复制出一条新数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const del = await Copy({ id: row.id })
          console.log(del)
          this.$message({
            type: 'success',
            message: '复制成功!'
          })

          this.onSearch()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消复制'
          })
        })
    },
    // 流程配置
    onClickprocess(row) {
      console.log(row)
      this.datarow = row
      this.visiblesSP = true
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  height: 30px;
  line-height: 30px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 14px;
  text-transform: uppercase;
  margin: 0 0 5px;
  padding: 0 10px;
  display: inline-block;
  letter-spacing: 0.5px;
}
</style>
